package ar.Location.UI;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import ar.Location.Constant.Define;
import ar.Location.Internet.NetworkStateReceiver;
import ar.Location.PlaceObject.PlaceCategory;
import ar.activity.R;

public class DataFilterItemView extends LinearLayout {

	//private static final String TAG = "DataFilterItemView";
	Context itemContext = null;
	TextView txtViewName = null;
	TextView txtDataFilterCount = null;
	ImageView imgViewIcon = null;
	ProgressBar progressBar = null;
	String[] strArrays = null;
	
	public DataFilterItemView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initContext(context);
		initView();
	}

	private void initContext(Context context) {
		// TODO Auto-generated method stub
		itemContext = context;		
		strArrays = itemContext.getResources().getStringArray(R.array.place_category_array);
	}

	public void initView() {
		inflate(itemContext, R.layout.data_filter_item, this);

		txtViewName = (TextView) findViewById(R.id.txtDataFilterName);
		txtDataFilterCount = (TextView) findViewById(R.id.txtDataFilterCount);
		imgViewIcon = (ImageView) findViewById(R.id.imgViewDataFilter);
		imgViewIcon.setAlpha(96);
		progressBar = (ProgressBar) findViewById(R.id.progressBarDataFilter);
	}

	public void bindData(PlaceCategory placeCategory) {
		// TODO Auto-generated method stub

		if (placeCategory != null) {
			if (placeCategory.isFinishLoading()) {

				int nResults = placeCategory.count();
				String count = String.valueOf(nResults);
				imgViewIcon.setAlpha(255);
				txtDataFilterCount.setText(count);
				progressBar.setVisibility(View.GONE);
				txtDataFilterCount.setVisibility(View.VISIBLE);
			} else {
				imgViewIcon.setAlpha(96);
				if (NetworkStateReceiver.isNetworkConnected) {
					progressBar.setVisibility(View.VISIBLE);
				} else {
					progressBar.setVisibility(View.GONE);
				}
				txtDataFilterCount.setVisibility(View.GONE);
			}

			if (txtViewName != null) {
				
				txtViewName.setText(strArrays[placeCategory.categoryIndex]);
			}

			if (imgViewIcon != null) {
				imgViewIcon
						.setImageResource(Define.listDataFilterIcons[placeCategory.categoryIndex]);
			}
		}
	}
}
